
#include "shogicommand.h"



ShogiCommand::ShogiCommand(int p ) : m_player(p) 
{

};

bool ShogiCommand::parseCommand(QByteArray* pCommand)
{
	bool bResult = true;

	int j = pCommand->indexOf("=");
	int semi = pCommand->indexOf(";");

	if (j>0)
	{
		m_command = pCommand->left(j);
		m_value = pCommand->mid(j+1,semi-j-1);
		//m_value = pCommand->mid(j+1,pCommand->size()-(j+2));
		
	}
	else
	{
		//m_command = pCommand->left(pCommand->size()-1);	
		m_command = pCommand->left(semi);
		m_value = "";
	}
	*pCommand = pCommand->left(pCommand->size()-semi-1); // Keep any remaining data

	return bResult;
}

void ShogiCommand::setCommand(QString command)
{
	m_command = command;
	m_value = "no_value_available";
}

void ShogiCommand::setCommandAndValue(QString command, QString value) 
{ 
	m_command = command; 
	m_value = value;
}

QString ShogiCommand::getCommandAndValue() const  
{ 
	QString str;
	if (m_value.compare("no_value_available")==0)
	{
			str = m_command; 
			str += ";";
	}
	else
	{	
		str = m_command; 
		str += "=";
		str += m_value; 
		str += ";";
	}
	
	return str;
}


QByteArray ShogiCommand::getFullCommand() const
{
	QByteArray tmp;
	if (m_value.compare("no_value_available")==0)
	{
		tmp = (m_command + ";").toAscii();
	}
	else
	{
		tmp = (m_command + "=" + m_value + ";").toAscii();
	}

	return tmp;
}
